﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RazzzorTest.Models;

namespace RazzzorTest.Controllers
{
    public class NewsController : Controller
    {
        BlogDataContext repo = new BlogDataContext();
        //
        // GET: /News/

        public ActionResult Index()
        {
            var news = repo.News.Take(5).ToList();
            return View(news);
        }

        //
        // GET: /News/Details/5

        public ActionResult Details(int id)
        {
            var news = repo.News.FirstOrDefault(t => t.ID == id);
            return View(news);
        }

        //
        // GET: /News/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /News/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            New n = new New();
            n.AddDate = DateTime.Now;
            n.Content = collection["content"];
            n.Title = collection["title"];
            repo.News.InsertOnSubmit(n);
            repo.SubmitChanges();
            return RedirectToAction("Index");
        }

        //
        // GET: /News/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /News/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            return View();
        }

        //
        // GET: /News/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /News/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            return View();
        }
    }
}
